package cn.hs.controller;

import cn.hs.entity.Usermark;
import cn.hs.mapper.UsermarkMapper;
import cn.hs.service.UsermarkService;
import cn.hs.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName UserMarkController
 * @Description TODO
 * @Author CnYuu
 * @Date 2024年10月24日 17:49
 * @Version 1.0
 */
@RestController
@RequestMapping("/usermark")
public class UsermarkController {
    @Autowired
    private UsermarkService service;
    @GetMapping("/selectAll")
    public Object selectAll(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "5") Integer pageSize
    ){
        PageInfo<Usermark> pageInfo = service.selctAll(pageNum, pageSize);
        return Result.success(pageInfo);
    }
    @GetMapping("/selectUserId")
    public Object selectUserId(
            @RequestParam(defaultValue = "1")Integer userId
    ){
        List<Usermark> usermarks = service.selectByUserId(userId);
        return Result.success(usermarks);
    }
    @GetMapping("/selectByConsultId")
    public Object selectByConsultId(
            @RequestParam Integer consultId
    ){
        List<Usermark> usermarks = service.selectByConsultId(consultId);
        return Result.success(usermarks);
    }
    @GetMapping("/selectById")

    public Object selectById(
            Usermark usermark
    ){
        Usermark usermark1 = service.selectById(usermark.getId());
        if(usermark1!=null){
            return Result.success(usermark1);
        }else {
            return Result.error("查询失败！");
        }
    }
    @PostMapping("/insert")
    public Object insert(@RequestBody Usermark usermark){
        int insert = service.insert(usermark);
        if(insert!=0){
            return Result.success("添加成功");
        }else {
            return Result.error("添加失败");
        }
    }
    @PostMapping("/delete")
    public Object delete(@RequestBody Usermark usermark){
        int delete = service.delete(usermark.getId());
        if(delete!=0){
            return Result.success("删除成功");
        }else {
            return Result.error("删除失败");
        }
    }
}
